<?php
include('inc/Images.php');
class Images 
{
	protected $_Imager;
	protected $_Pict;

	
	public function __construct()
	{
		$this->_Imager = new Imager();
		$this->_Pict = new Zend_Db_Table('pictures'); 
	}
	
	
	
	public function processImage($Name,$Description,$AID, $tmpPath,$Tag = '',$Video = 0)
	{
            //  Копирование в репозиторий изображений
        
		$NewName  = md5(time() . $tmpPath);
        $info     = pathinfo($tmpPath);
		$NewName .=  "." . $info['extension'];
		
		//$this->_Imager->cropImage(100,100,$tmpPath,'jpg',ROOT_PATH . "/images/100/" . $NewName);
		
		$this->_Imager->load($tmpPath);
		$this->_Imager->intelliResize(100);
		$this->_Imager->save(ROOT_PATH . "/images/100/" . $NewName,IMAGETYPE_JPEG,90,0777);
		
        $this->_Imager->load($tmpPath);
        $this->_Imager->resizeToWidth(650);
        $this->_Imager->save(ROOT_PATH . "/images/full/" . $NewName,IMAGETYPE_JPEG,90,0777);
		
		
		
		//copy($tmpPath,ROOT_PATH . "/images/full/" . $NewName);
		$Params = array(
		               'Filename'=>$NewName,
		               'Name'=>$Name,
		               'AID'=>$AID,
		               'Description'=>$Description, 
		              'Tag'=>$Tag,
		              'Video'=>$Video     
		               );
		$Row = $this->_Pict->createRow($Params);
		$Row->save();
		
		$this->_Pict->delete('AID=' . $AID . ' AND Filename="empty.png"');
		
		return $Row->ID;
	}

	
	
	
}